package com.zjj.edu.system.service.impl;

import com.zjj.edu.common.constant.UserConstants;
import com.zjj.edu.common.utils.DateUtils;
import com.zjj.edu.common.utils.StringUtils;
import com.zjj.edu.system.domain.SysCourseGoods;
import com.zjj.edu.system.domain.SysTeachGoods;
import com.zjj.edu.system.mapper.SysTeachGoodsMapper;
import com.zjj.edu.system.service.ISysTeachGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 教学物品Service业务层处理
 *
 * @author zjj
 * @date 2020-06-02
 */
@Service
public class SysTeachGoodsServiceImpl implements ISysTeachGoodsService
{
    @Autowired
    private SysTeachGoodsMapper sysTeachGoodsMapper;

    /**
     * 查询教学物品
     *
     * @param id 教学物品ID
     * @return 教学物品
     */
    @Override
    public SysTeachGoods selectSysTeachGoodsById(Long id)
    {
        return sysTeachGoodsMapper.selectSysTeachGoodsById(id);
    }

    /**
     * 查询教学物品列表
     *
     * @param sysTeachGoods 教学物品
     * @return 教学物品
     */
    @Override
    public List<SysTeachGoods> selectSysTeachGoodsList(SysTeachGoods sysTeachGoods)
    {
        return sysTeachGoodsMapper.selectSysTeachGoodsList(sysTeachGoods);
    }

    @Override
    public List<SysCourseGoods> selectSysCourseGoodsById(Long id) {
        return sysTeachGoodsMapper.selectSysCourseGoodsById(id);
    }

    @Override
    public List<SysTeachGoods> selectSysTeachGoodsListByIds(SysTeachGoods sysTeachGoods) {
        return sysTeachGoodsMapper.selectSysTeachGoodsListByIds(sysTeachGoods);
    }

    /**
     * 新增教学物品
     *
     * @param sysTeachGoods 教学物品
     * @return 结果
     */
    @Override
    public int insertSysTeachGoods(SysTeachGoods sysTeachGoods)
    {
        sysTeachGoods.setCreateTime(DateUtils.getNowDate());
        return sysTeachGoodsMapper.insertSysTeachGoods(sysTeachGoods);
    }

    /**
     * 修改教学物品
     *
     * @param sysTeachGoods 教学物品
     * @return 结果
     */
    @Override
    public int updateSysTeachGoods(SysTeachGoods sysTeachGoods)
    {
        sysTeachGoods.setUpdateTime(DateUtils.getNowDate());
        return sysTeachGoodsMapper.updateSysTeachGoods(sysTeachGoods);
    }

    /**
     * 删除教学物品对象
     *
     * @return 结果
     */
    @Override
    public int deleteSysTeachGoodsByIds(SysTeachGoods sysTeachGoods)
    {
        return sysTeachGoodsMapper.deleteSysTeachGoodsByIds(sysTeachGoods);
    }

    @Override
    public int removeCourseGoods(Long id) {
        return sysTeachGoodsMapper.removeCourseGoods(id);
    }

    @Override
    public String checkNameUnique(SysTeachGoods vo) {
        Long id = StringUtils.isNull(vo.getId()) ? -1L : vo.getId();
        SysTeachGoods info = sysTeachGoodsMapper.checkNameUnique(vo.getName(), vo.getTenantId());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
        {
            return UserConstants.NAME_NOT_UNIQUE;
        }
        return UserConstants.NAME_UNIQUE;
    }
}
